// pages/member/member.js
import request from '../../utils/request'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    member:[],
    pageSize:1,
    pageNum:6,
    isPull:true,
    indicatorDots: true,
    autoplay: true,
    interval: 2000,
    duration: 500
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var page = this.data.pageSize
   this.getMember(page)
   this.getIndexImg()
  },
  getMember:function(page){
    var that = this
    // 会员风采 
    var data = {
      page:page,
      limit:that.data.pageNum
    }
    request.get('article/list/5',data,{ noAuth : true}).then(res=>{
      console.log(res.data)
      if(res.data.length>0){
        that.setData({
          member:that.data.member.concat(res.data)
        })
      }else{
        that.setData({
          isPull:false
        })
      }
    })

  },
  register:function(){
    wx.getSetting({
      success(res){
       if(res.authSetting['scope.userInfo']){
       var u =  wx.getStorageSync('userInfo')
        var is_company = u.is_company
        console.log(is_company)
        if(is_company==1){
          wx.showToast({
            title: '企业已通过认证',
            icon:'success'
          })
          return
        }else if(is_company==2){
          wx.showLoading({
            title: '认证审核中....',
          })
          setTimeout(function(){
            wx.hideLoading()
          },1000)
          return
        }else{
          wx.navigateTo({
            url: '/pages/businessIdent/businessIdent',
          })
        }

      
       }else{
         wx.showModal({
           content: '请前往【个人中心】登录授权',
           success(res){
             if(res.confirm){
               setTimeout(() => {
                   wx.switchTab({
                        url: '../user/user',
                      })
               }, 500);
             }
           }
         })
       }
      }
    })
  },
  details:function(d){
    var id = d.currentTarget.dataset.id
    wx.navigateTo({
      url: './business_details/business_details?id='+id,
    })
  },
  getIndexImg:function(){
    request.get('banner/user_register',{},{ noAuth : true}).then(res=>{
      console.log(res)
      this.setData({
        background:res.data
      })
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var value = this.data
    if(value.isPull){
      var nextPage = ++value.pageSize
      this.getMember(nextPage)
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})